#ifndef MESH_H
#define MESH_H

#include <QVector>
#include <QVector3D>
#include "vrml2parser.h"
#include <GL/gl.h>

class MeshVertex
{
public:
    GLfloat point[3];
    GLfloat normal[3];
    GLfloat color[3];
};

class MeshFace
{
public:
    QVector<MeshVertex*> vertices;
    GLfloat normal[3];
    GLfloat color[3];
};

class MeshMaterial
{
public:
    GLfloat ambientColor[4];
    GLfloat diffuseColor[4];
    GLfloat emissiveColor[4];
    GLfloat specularColor[4];
    GLfloat shininess;
};

class MeshShape
{
public:
    QVector<MeshVertex*> vertices;
    QVector<MeshFace*> faces;
    MeshMaterial material;
    bool normalPerVertex;

    ~MeshShape()
    {
        for (int i=0; i<faces.count(); i++)
            delete faces[i];
        faces.clear();
        for (int i=0; i<vertices.count(); i++)
            delete vertices[i];
        vertices.clear();
    }
};

class Mesh
{
private:
    QVector<MeshShape*> Shapes;

    void loadVrml2(QTextStream *stream);
    void loadChildren(GroupingNode *par);
    void loadShape(Shape *node);

public:
    explicit Mesh();
    Mesh(QTextStream *stream);
    virtual ~Mesh();

    void clear();
    void load(QTextStream *stream);
    inline QVector<MeshShape*>& shapes() {return Shapes;}

    //void operator =(Mesh &mesh);
    void copy(Mesh *mesh);
};

#endif // MESH_H
